package cn.chair.controller.admin;

import cn.chair.annotation.PublicApi;
import cn.chair.model.admin.RegionResp;
import life.innovation.util.IOUtil;
import life.innovation.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "")
public class RegionController {

    private static final String regionConfigFile = "city.json";
    private static List<RegionResp> regions = getRegions();



    public static List<RegionResp> getRegions() {

        if (regions == null) {
            String value = IOUtil.getResource(RegionController.class.getClassLoader().getResourceAsStream(regionConfigFile));
            return JsonUtil.toModels(value, RegionResp.class);
        }

        return regions;
    }

    @PublicApi
    @GetMapping(value="getRegion")
    public List<RegionResp> getCity(){
        List<RegionResp> regionList = getRegions();

        return regionList;
    }
}
